<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<script type="text/javascript">
<!--
	$(function(){
		//数据列表
		var dg = $("#mgr_class_dg").datagrid({
			url:"${pageContext.request.contextPath}/mgr/class!datagrid.action",
			fit:true,
			fitColumns:true,
			pagination:true,
			pagePosition:"bottom",
			pageSize:20,
			pageList:[20,30,40],
			border:false,
			idField:"id",
			sortName:"name",
			sortOrder:"asc",
			columns:[[{
				field:"id",
				checkbox:true
			},{
				title:"所属学校单位",
				field:"unitName",
				width:128,
				sortable:true
			},{
				title:"当前年级",
				field:"gradeValue",
				width:20,
				sortable:true
			},{
				title:"班级代码",
				field:"code",
				width:64,
				sortable:true
			},{
				title:"班级名称",
				field:"name",
				width:64,
				sortable:true
			},{
				title:"入学年份",
				field:"joinYear",
				width:32,
				sortable:true
			}]],
			toolbar:"#mgr_class_dg_toolbar",
			onDblClickRow:function(rowIndex,rowData){
				mgr_class_edit_window("编辑班级",rowIndex,rowData);
			}
		});
		function mgr_class_edit_window(title,index,row){
			var d = $("<div/>").dialog({
				title:title,
				width:320,
				height:200,
				href:"${pageContext.request.contextPath}/mgr/class!edit.action",
				modal:true,
				buttons:[{
					text:"保存",
					iconCls:"icon-save",
					handler:function(){
						$("#mgr_classedit_form").form("submit",{
							url:"${pageContext.request.contextPath}/mgr/class!update.action",
							success:function(data){
								var data = jQuery.parseJSON(data);
								if(data.success){
									dg.datagrid(row ? "updateRow" : "insertRow",{
										index:index,
										row:data.data
									});
									d.dialog("close");
								}else{
									$.messager.show({
										title:"保存异常",
										msg:data.msg
									});
								}
							}
						});
					}
				},{
					text:"关闭",
					iconCls:"icon-cancel",
					handler:function(){
						d.dialog("close");
					}
				}],
				onClose:function(){
					$(this).dialog("destroy");
				},
				onLoad:function(){
					if(row){
						$("#mgr_classedit_form").form("load",row);
					}
				}
			});
		};
		//查询
		mgr_class_dg_search = function(){
			dg.datagrid("load",{
				name:$("#mgr_class_dg_toolbar input[type=text]").val()
			});
		};
		//新增
		mgr_class_dg_add = function(){
			mgr_class_edit_window("新增班级",0,null);
		};
		//删除
		mgr_class_dg_delete = function(){
			var rows = dg.datagrid("getChecked");
			if(rows && rows.length > 0){
				$.messager.confirm("确认","您是否确认删除选中的数据?",function(r){
					if(!r)return;
					var ids = [];
					for(var i = 0; i < rows.length; i++){
						ids.push(rows[i].id);
					}
					$.ajax({
						url:"${pageContext.request.contextPath}/mgr/class!delete.action",
						type:"POST",
						data:{
							id:ids.join("|")
						},
						dataType:"json",
						success:function(data,textStatus){
							if(data.success){
								dg.datagrid("load");
								dg.datagrid("unselectAll");
							}else{
								$.messager.show({
									title:"提示",
									msg:data.msg
								});
							}
						}
					});
				});
			}else{
				$.messager.alert("提示","未选中须删除的数据！");
			}
		};
	});
//-->
</script>
<table id="mgr_class_dg"></table>
<div id="mgr_class_dg_toolbar">
	<a href="#" class="easyui-linkbutton" onclick="mgr_class_dg_add()" data-options="iconCls:'icon-add',plain:true" style="float:left;">新增</a>
	<div class="datagrid-btn-separator"></div>
	<a href="#" class="easyui-linkbutton" onclick="mgr_class_dg_delete()" data-options="iconCls:'icon-remove',plain:true">删除</a>
	<div class="datagrid-btn-separator"></div>
	<span>班级名称:</span>
	<input type="text"  style="width:268px;"/>
	<a href="#" class="easyui-linkbutton" onclick="mgr_class_dg_search()" data-options="iconCls:'icon-search',plain:true">查询</a>
</div>